home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / gnu / a2_0bEmacs_bin.lha / Emacs-19.25 / info / emacs-11 (.txt) < prev    next >
GNU Info File  |  1992-02-21  |  49KB  |  868 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.43 from the
  2. input file emacs.tex.
  3.    This file documents the GNU Emacs editor.
  4.    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.
  5.    Permission is granted to make and distribute verbatim copies of
  6. this manual provided the copyright notice and this permission notice
  7. are preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
  11. General Public License" are included exactly as in the original, and
  12. provided that the entire resulting derived work is distributed under
  13. the terms of a permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the sections entitled "The GNU Manifesto",
  17. "Distribution" and "GNU General Public License" may be included in a
  18. translation approved by the author instead of in the original English.
  19. File: emacs,  Node: Customization,  Next: Quitting,  Prev: Emulation,  Up: Top
  20. Customization
  21. *************
  22.    This chapter talks about various topics relevant to adapting the
  23. behavior of Emacs in minor ways.
  24.    All kinds of customization affect only the particular Emacs job
  25. that you do them in.  They are completely lost when you kill the Emacs
  26. job, and have no effect on other Emacs jobs you may run at the same
  27. time or later.  The only way an Emacs job can affect anything outside
  28. of it is by writing a file; in particular, the only way to make a
  29. customization `permanent' is to put something in your `.emacs' file or
  30. other appropriate file to do the customization in each session.  *Note
  31. Init File::.
  32. * Menu:
  33. * Minor Modes::     Each minor mode is one feature you can turn on
  34.                      independently of any others.
  35. * Variables::       Many Emacs commands examine Emacs variables
  36.                      to decide what to do; by setting variables,
  37.                      you can control their functioning.
  38. * Keyboard Macros:: A keyboard macro records a sequence of keystrokes
  39.                      to be replayed with a single command.
  40. * Key Bindings::    The keymaps say what command each key runs.
  41.                      By changing them, you can "redefine keys".
  42. * Syntax::          The syntax table controls how words and expressions
  43.                      are parsed.
  44. * Init File::       How to write common customizations in the `.emacs' file.
  45. File: emacs,  Node: Minor Modes,  Next: Variables,  Prev: Customization,  Up: Customization
  46. Minor Modes
  47. ===========
  48.    Minor modes are options which you can use or not.  For example,
  49. Auto Fill mode is a minor mode in which SPC breaks lines between words
  50. as you type.  All the minor modes are independent of each other and of
  51. the selected major mode.  Most minor modes say in the mode line when
  52. they are on; for example, `Fill' in the mode line means that Auto Fill
  53. mode is on.
  54.    Append `-mode' to the name of a minor mode to get the name of a
  55. command function that turns the mode on or off.  Thus, the command to
  56. enable or disable Auto Fill mode is called `M-x auto-fill-mode'.  These
  57. commands are usually invoked with `M-x', but you can bind keys to them
  58. if you wish.  With no argument, the function turns the mode on if it
  59. was off and off if it was on.  This is known as "toggling".  A positive
  60. argument always turns the mode on, and an explicit zero argument or a
  61. negative argument always turns it off.
  62.    Auto Fill mode allows you to enter filled text without breaking
  63. lines explicitly.  Emacs inserts newlines as necessary to prevent
  64. lines from becoming too long.  *Note Filling::.
  65.    Overwrite mode causes ordinary printing characters to replace
  66. existing text instead of shoving it over.  For example, if the point
  67. is in front of the `B' in `FOOBAR', then in Overwrite mode typing a `G'
  68. changes it to `FOOGAR', instead of making it `FOOGBAR' as usual.
  69.    Abbrev mode allows you to define abbreviations that automatically
  70. expand as you type them.  For example, `amd' might expand to `abbrev
  71. mode'.  *Note Abbrevs::, for full information.
  72. File: emacs,  Node: Variables,  Next: Keyboard Macros,  Prev: Minor Modes,  Up: Customization
  73. Variables
  74. =========
  75.    A "variable" is a Lisp symbol which has a value.  The symbol's name
  76. is also called the name of the variable.  Variable names can contain
  77. any characters, but conventionally they are chosen to be words
  78. separated by hyphens.  A variable can have a documentation string
  79. which describes what kind of value it should have and how the value
  80. will be used.
  81.    Lisp allows any variable to have any kind of value, but most
  82. variables that Emacs uses require a value of a certain type.  Often
  83. the value should always be a string, or should always be a number. 
  84. Sometimes we say that a certain feature is turned on if a variable is
  85. "non-`nil'," meaning that if the variable's value is `nil', the
  86. feature is off, but the feature is on for any other value.  The
  87. conventional value to use to turn on the feature--since you have to
  88. pick one particular value when you set the variable--is `t'.
  89.    Emacs uses many Lisp variables for internal recordkeeping, as any
  90. Lisp program must, but the most interesting variables for you are the
  91. ones that exist for the sake of customization.  Emacs does not
  92. (usually) change the values of these variables; instead, you set the
  93. values, and thereby alter and control the behavior of certain Emacs
  94. commands.  These variables are called "options".  Most options are
  95. documented in this manual, and appear in the Variable Index (*note
  96. Variable Index::.).
  97.    One example of a variable which is an option is `fill-column', which
  98. specifies the position of the right margin (as a number of characters
  99. from the left margin) to be used by the fill commands (*note
  100. Filling::.).
  101. * Menu:
  102. * Examining::           Examining or setting one variable's value.
  103. * Edit Options::        Examining or editing list of all variables' values.
  104. * Locals::              Per-buffer values of variables.
  105. * File Variables::      How files can specify variable values.
  106. File: emacs,  Node: Examining,  Next: Edit Options,  Prev: Variables,  Up: Variables
  107. Examining and Setting Variables
  108. -------------------------------
  109. `C-h v'
  110. `M-x describe-variable'
  111.      Print the value and documentation of a variable.
  112. `M-x set-variable'
  113.      Change the value of a variable.
  114.    To examine the value of a single variable, use `C-h v'
  115. (`describe-variable'), which reads a variable name using the
  116. minibuffer, with completion.  It prints both the value and the
  117. documentation of the variable.
  118.      C-h v fill-column RET
  119. prints something like
  120.      fill-column's value is 75
  121.      
  122.      Documentation:
  123.      *Column beyond which automatic line-wrapping should happen.
  124.      Automatically becomes local when set in any fashion.
  125. The star at the beginning of the documentation indicates that this
  126. variable is an option.  `C-h v' is not restricted to options; it
  127. allows any variable name.
  128.    If you know which option you want to set, you can set it using `M-x
  129. set-variable'.  This reads the variable name with the minibuffer (with
  130. completion), and then reads a Lisp expression for the new value using
  131. the minibuffer a second time.  For example,
  132.      M-x set-variable RET fill-column RET 75 RET
  133. sets `fill-column' to 75, like executing the Lisp expression
  134.      (setq fill-column 75)
  135.    Setting variables in this way, like all means of customizing Emacs
  136. except where explicitly stated, affects only the current Emacs session.
  137. File: emacs,  Node: Edit Options,  Next: Locals,  Prev: Examining,  Up: Variables
  138. Editing Variable Values
  139. -----------------------
  140. `M-x list-options'
  141.      Display a buffer listing names, values and documentation of all
  142.      options.
  143. `M-x edit-options'
  144.      Change option values by editing a list of options.
  145.    `M-x list-options' displays a list of all Emacs option variables, in
  146. an Emacs buffer named `*List Options*'.  Each option is shown with its
  147. documentation and its current value.  Here is what a portion of it
  148. might look like:
  149.      ;; exec-path:
  150.      ("." "/usr/local/bin" "/usr/ucb" "/bin" "/usr/bin" "/u2/emacs/etc")
  151.      *List of directories to search programs to run in subprocesses.
  152.      Each element is a string (directory name)
  153.      or nil (try the default directory).
  154.      ;;
  155.      ;; fill-column:
  156.      75
  157.      *Column beyond which automatic line-wrapping should happen.
  158.      Automatically becomes local when set in any fashion.
  159.      ;;
  160.    `M-x edit-options' goes one step further and immediately selects the
  161. `*List Options*' buffer; this buffer uses the major mode Options mode,
  162. which provides commands that allow you to point at an option and
  163. change its value:
  164.      Set the variable point is in or near to a new value read using the
  165.      minibuffer.
  166.      Toggle the variable point is in or near: if the value was `nil',
  167.      it becomes `t'; otherwise it becomes `nil'.
  168.      Set the variable point is in or near to `t'.
  169.      Set the variable point is in or near to `nil'.
  170.      Move to the next or previous variable.
  171. File: emacs,  Node: Locals,  Next: File Variables,  Prev: Edit Options,  Up: Variables
  172. Local Variables
  173. ---------------
  174. `M-x make-local-variable'
  175.      Make a variable have a local value in the current buffer.
  176. `M-x kill-local-variable'
  177.      Make a variable use its global value in the current buffer.
  178. `M-x make-variable-buffer-local'
  179.      Mark a variable so that setting it will make it local to the
  180.      buffer that is current at that time.
  181.    Any variable can be made "local" to a specific Emacs buffer.  This
  182. means that its value in that buffer is independent of its value in
  183. other buffers.  A few variables are always local in every buffer. 
  184. Every other Emacs variable has a "global" value which is in effect in
  185. all buffers that have not made the variable local.
  186.    Major modes always make the variables they set local to the buffer. 
  187. This is why changing major modes in one buffer has no effect on other
  188. buffers.
  189.    `M-x make-local-variable' reads the name of a variable and makes it
  190. local to the current buffer.  Further changes in this buffer will not
  191. affect others, and further changes in the global value will not affect
  192. this buffer.
  193.    `M-x make-variable-buffer-local' reads the name of a variable and
  194. changes the future behavior of the variable so that it will become
  195. local automatically when it is set.  More precisely, once a variable
  196. has been marked in this way, the usual ways of setting the variable
  197. will automatically do `make-local-variable' first.  We call such
  198. variables "per-buffer" variables.
  199.    Some important variables have been marked per-buffer already. 
  200. These include `abbrev-mode', `auto-fill-hook', `case-fold-search',
  201. `comment-column', `ctl-arrow', `fill-column', `fill-prefix',
  202. `indent-tabs-mode', `left-margin', `mode-line-format',
  203. `overwrite-mode',
  204.  `selective-display-ellipses', `selective-display', `tab-width', and
  205. `truncate-lines'.  Some other variables are always local in every
  206. buffer, but they are used for internal purposes.
  207.    `M-x kill-local-variable' reads the name of a variable and makes it
  208. cease to be local to the current buffer.  The global value of the
  209. variable henceforth is in effect in this buffer.  Setting the major
  210. mode kills all the local variables of the buffer.
  211.    To set the global value of a variable, regardless of whether the
  212. variable has a local value in the current buffer, you can use the Lisp
  213. function `setq-default'.  It works like `setq'.  If there is a local
  214. value in the current buffer, the local value is not affected by
  215. `setq-default'; thus, the new global value may not be visible until
  216. you switch to another buffer.  For example,
  217.      (setq-default fill-column 75)
  218. `setq-default' is the only way to set the global value of a variable
  219. that has been marked with `make-variable-buffer-local'.
  220.    Programs can look at a variable's default value with
  221. `default-value'.  This function takes a symbol as argument and returns
  222. its default value.  The argument is evaluated; usually you must quote
  223. it explicitly.  For example,
  224.      (default-value 'fill-column)
  225. File: emacs,  Node: File Variables,  Prev: Locals,  Up: Variables
  226. Local Variables in Files
  227. ------------------------
  228.    A file can contain a "local variables list", which specifies the
  229. values to use for certain Emacs variables when that file is edited. 
  230. Visiting the file checks for a local variables list and makes each
  231. variable in the list local to the buffer in which the file is visited,
  232. with the value specified in the file.
  233.    A local variables list goes near the end of the file, in the last
  234. page.  (It is often best to put it on a page by itself.)  The local
  235. variables list starts with a line containing the string `Local
  236. Variables:', and ends with a line containing the string `End:'.  In
  237. between come the variable names and values, one set per line, as
  238. `VARIABLE: VALUE'.  The VALUEs are not evaluated; they are used
  239. literally.
  240.    The line which starts the local variables list does not have to say
  241. just `Local Variables:'.  If there is other text before `Local
  242. Variables:', that text is called the "prefix", and if there is other
  243. text after, that is called the "suffix".  If these are present, each
  244. entry in the local variables list should have the prefix before it and
  245. the suffix after it.  This includes the `End:' line.  The prefix and
  246. suffix are included to disguise the local variables list as a comment
  247. so that the compiler or text formatter will not be perplexed by it. 
  248. If you do not need to disguise the local variables list as a comment
  249. in this way, do not bother with a prefix or a suffix.
  250.    Two "variable" names are special in a local variables list: a value
  251. for the variable `mode' really sets the major mode, and a value for the
  252. variable `eval' is simply evaluated as an expression and the value is
  253. ignored.  These are not real variables; setting such variables in any
  254. other context has no such effect.  If `mode' is used in a local
  255. variables list, it should be the first entry in the list.
  256.    Here is an example of a local variables list:
  257.      ;;; Local Variables: ***
  258.      ;;; mode:lisp ***
  259.      ;;; comment-column:0 ***
  260.      ;;; comment-start: ";;; "  ***
  261.      ;;; comment-end:"***" ***
  262.      ;;; End: ***
  263.    Note that the prefix is `;;; ' and the suffix is ` ***'.  Note also
  264. that comments in the file begin with and end with the same strings. 
  265. Presumably the file contains code in a language which is like Lisp
  266. (like it enough for Lisp mode to be useful) but in which comments start
  267. and end in that way.  The prefix and suffix are used in the local
  268. variables list to make the list appear as comments when the file is
  269. read by the compiler or interpreter for that    language.
  270.    The start of the local variables list must be no more than 3000
  271. characters from the end of the file, and must be in the last page if
  272. the file is divided into pages.  Otherwise, Emacs will not notice it
  273. is there.  The purpose of this is so that a stray `Local Variables:'
  274. not in the last page does not confuse Emacs, and so that visiting a
  275. long file that is all one page and has no local variables list need
  276. not take the time to search the whole file.
  277.    You may be tempted to try to turn on Auto Fill mode with a local
  278. variable list.  That is a mistake.  The choice of Auto Fill mode or
  279. not is a matter of individual taste, not a matter of the contents of
  280. particular files.  If you want to use Auto Fill, set up major mode
  281. hooks with your `.emacs' file to turn it on (when appropriate) for you
  282. alone (*note Init File::.).  Don't try to use a local variable list
  283. that would impose your taste on everyone.
  284. File: emacs,  Node: Keyboard Macros,  Next: Key Bindings,  Prev: Variables,  Up: Customization
  285. Keyboard Macros
  286. ===============
  287.    A "keyboard macro" is a command defined by the user to abbreviate a
  288. sequence of keys.  For example, if you discover that you are about to
  289. type `C-n C-d' forty times, you can speed your work by defining a
  290. keyboard macro to do `C-n C-d' and calling it with a repeat count of
  291. forty.
  292. `C-x ('
  293.      Start defining a keyboard macro (`start-kbd-macro').
  294. `C-x )'
  295.      End the definition of a keyboard macro (`end-kbd-macro').
  296. `C-x e'
  297.      Execute the most recent keyboard macro (`call-last-kbd-macro').
  298. `C-u C-x ('
  299.      Re-execute last keyboard macro, then add more keys to its
  300.      definition.
  301. `C-x q'
  302.      When this point is reached during macro execution, ask for
  303.      confirmation (`kbd-macro-query').
  304. `M-x name-last-kbd-macro'
  305.      Give a command name (for the duration of the session) to the most
  306.      recently defined keyboard macro.
  307. `M-x insert-kbd-macro'
  308.      Insert in the buffer a keyboard macro's definition, as Lisp code.
  309.    Keyboard macros differ from ordinary Emacs commands in that they are
  310. written in the Emacs command language rather than in Lisp.  This makes
  311. it easier for the novice to write them, and makes them more convenient
  312. as temporary hacks.  However, the Emacs command language is not
  313. powerful enough as a programming language to be useful for writing
  314. anything intelligent or general.  For such things, Lisp must be used.
  315.    You define a keyboard macro while executing the commands which are
  316. the definition.  Put differently, as you are defining a keyboard
  317. macro, the definition is being executed for the first time.  This way,
  318. you can see what the effects of your commands are, so that you don't
  319. have to figure them out in your head.  When you are finished, the
  320. keyboard macro is defined and also has been, in effect, executed once.
  321.  You can then do the whole thing over again by invoking the macro.
  322. * Menu:
  323. * Basic Kbd Macro::     Defining and running keyboard macros.
  324. * Save Kbd Macro::      Giving keyboard macros names; saving them in files.
  325. * Kbd Macro Query::     Keyboard macros that do different things each use.
  326. File: emacs,  Node: Basic Kbd Macro,  Next: Save Kbd Macro,  Prev: Keyboard Macros,  Up: Keyboard Macros
  327. Basic Use
  328. ---------
  329.    To start defining a keyboard macro, type the `C-x (' command
  330. (`start-kbd-macro').  From then on, your keys continue to be executed,
  331. but also become part of the definition of the macro.  `Def' appears in
  332. the mode line to remind you of what is going on.  When you are
  333. finished, the `C-x )' command (`end-kbd-macro') terminates the
  334. definition (without becoming part of it!).  For example
  335.      C-x ( M-F foo C-x )
  336. defines a macro to move forward a word and then insert `foo'.
  337.    The macro thus defined can be invoked again with the `C-x e' command
  338. (`call-last-kbd-macro'), which may be given a repeat count as a
  339. numeric argument to execute the macro many times.  `C-x )' can also be
  340. given a repeat count as an argument, in which case it repeats the macro
  341. that many times right after defining it, but defining the macro counts
  342. as the first repetition (since it is executed as you define it).  So,
  343. giving `C-x )' an argument of 4 executes the macro immediately 3
  344. additional times.  An argument of zero to `C-x e' or `C-x )' means
  345. repeat the macro indefinitely (until it gets an error or you type
  346. `C-g').
  347.    If you wish to repeat an operation at regularly spaced places in the
  348. text, define a macro and include as part of the macro the commands to
  349. move to the next place you want to use it.  For example, if you want
  350. to change each line, you should position point at the start of a line,
  351. and define a macro to change that line and leave point at the start of
  352. the next line.  Then repeating the macro will operate on successive
  353. lines.
  354.    After you have terminated the definition of a keyboard macro, you
  355. can add to the end of its definition by typing `C-u C-x ('.  This is
  356. equivalent to plain `C-x (' followed by retyping the whole definition
  357. so far.  As a consequence it re-executes the macro as previously
  358. defined.
  359. File: emacs,  Node: Save Kbd Macro,  Next: Kbd Macro Query,  Prev: Basic Kbd Macro,  Up: Keyboard Macros
  360. Naming and Saving Keyboard Macros
  361. ---------------------------------
  362.    If you wish to save a keyboard macro for longer than until you
  363. define the next one, you must give it a name using `M-x
  364. name-last-kbd-macro'.  This reads a name as an argument using the
  365. minibuffer and defines that name to execute the macro.  The macro name
  366. is a Lisp symbol, and defining it in this way makes it a valid command
  367. name for calling with `M-x' or for binding a key to with
  368. `global-set-key' (*note Keymaps::.).  If you specify a name that has a
  369. prior definition other than another keyboard macro, an error message
  370. is printed and nothing is changed.
  371.    Once a macro has a command name, you can save its definition in a
  372. file.  Then it can be used in another editing session.  First visit
  373. the file you want to save the definition in.  Then use the command
  374.      M-x insert-kbd-macro RET MACRONAME RET
  375. This inserts some Lisp code that, when executed later, will define the
  376. same macro with the same definition it has now.  You need not
  377. understand Lisp code to do this, because `insert-kbd-macro' writes the
  378. Lisp code for you.  Then save the file.  The file can be loaded with
  379. `load-file' (*note Lisp Libraries::.).  If the file you save in is
  380. your init file `~/.emacs' (*note Init File::.) then the macro will be
  381. defined each time you run Emacs.
  382.    If you give `insert-kbd-macro' a prefix argument, it makes
  383. additional Lisp code to record the keys (if any) that you have bound
  384. to the keyboard macro, so that the macro will be reassigned the same
  385. keys when you load the file.
  386. File: emacs,  Node: Kbd Macro Query,  Prev: Save Kbd Macro,  Up: Keyboard Macros
  387. Executing Macros with Variations
  388. --------------------------------
  389.    Using `C-x q' (`kbd-macro-query'), you can get an effect similar to
  390. that of `query-replace', where the macro asks you each time around
  391. whether to make a change.  When you are defining the macro, type `C-x
  392. q' at the point where you want the query to occur.  During macro
  393. definition, the `C-x q' does nothing, but when the macro is invoked the
  394. `C-x q' reads a character from the terminal to decide whether to
  395. continue.
  396.    The special answers are SPC, DEL, `C-d', `C-l' and `C-r'.  Any
  397. other character terminates execution of the keyboard macro and is then
  398. read as a command.  SPC means to continue.  DEL means to skip the
  399. remainder of this repetition of the macro, starting again from the
  400. beginning in the next repetition.  `C-d' means to skip the remainder
  401. of this repetition and cancel further repetition.  `C-l' redraws the
  402. screen and asks you again for a character to say what to do.  `C-r'
  403. enters a recursive editing level, in which you can perform editing
  404. which is not part of the macro.  When you exit the recursive edit
  405. using `C-M-c', you are asked again how to continue with the keyboard
  406. macro.  If you type a SPC at this time, the rest of the macro
  407. definition is executed.  It is up to you to leave point and the text
  408. in a state such that the rest of the macro will do what you want.
  409.    `C-u C-x q', which is `C-x q' with a numeric argument, performs a
  410. different function.  It enters a recursive edit reading input from the
  411. keyboard, both when you type it during the definition of the macro, and
  412. when it is executed from the macro.  During definition, the editing
  413. you do inside the recursive edit does not become part of the macro. 
  414. During macro execution, the recursive edit gives you a chance to do
  415. some particularized editing.  *Note Recursive Edit::.
  416. File: emacs,  Node: Key Bindings,  Next: Syntax,  Prev: Keyboard Macros,  Up: Customization
  417. Customizing Key Bindings
  418. ========================
  419.    This section deals with the "keymaps" which define the bindings
  420. between keys and functions, and shows how you can customize these
  421. bindings.
  422.    A command is a Lisp function whose definition provides for
  423. interactive use.  Like every Lisp function, a command has a function
  424. name, a Lisp symbol whose name usually consists of lower case letters
  425. and hyphens.
  426. * Menu:
  427. * Keymaps::    Definition of the keymap data structure.
  428.                Names of Emacs's standard keymaps.
  429. * Rebinding::  How to redefine one key's meaning conveniently.
  430. * Disabling::  Disabling a command means confirmation is required
  431.                 before it can be executed.  This is done to protect
  432.                 beginners from surprises.
  433. File: emacs,  Node: Keymaps,  Next: Rebinding,  Prev: Key Bindings,  Up: Key Bindings
  434. Keymaps
  435. -------
  436.    The bindings between characters and command functions are recorded
  437. in data structures called "keymaps".  Emacs has many of these.  One,
  438. the "global" keymap, defines the meanings of the single-character keys
  439. that are defined regardless of major mode.  It is the value of the
  440. variable `global-map'.
  441.    Each major mode has another keymap, its "local keymap", which
  442. contains overriding definitions for the single-character keys that are
  443. to be redefined in that mode.  Each buffer records which local keymap
  444. is installed for it at any time, and the current buffer's local keymap
  445. is the only one that directly affects command execution.  The local
  446. keymaps for Lisp mode, C mode, and many other major modes always exist
  447. even when not in use.  They are the values of the variables
  448. `lisp-mode-map', `c-mode-map', and so on.  For major modes less often
  449. used, the local keymap is sometimes constructed only when the mode is
  450. used for the first time in a session.  This is to save space.
  451.    There are local keymaps for the minibuffer too; they contain various
  452. completion and exit commands.
  453.    * `minibuffer-local-map' is used for ordinary input (no completion).
  454.    * `minibuffer-local-ns-map' is similar, except that SPC exits just
  455.      like RET.  This is used mainly for Mocklisp compatibility.
  456.    * `minibuffer-local-completion-map' is for permissive completion.
  457.    * `minibuffer-local-must-match-map' is for strict completion and
  458.      for cautious completion.
  459.    * `repeat-complex-command-map' is for use in `C-x ESC'.
  460.    Finally, each prefix key has a keymap which defines the key
  461. sequences that start with it.  For example, `ctl-x-map' is the keymap
  462. used for characters following a `C-x'.
  463.    * `ctl-x-map' is the variable name for the map used for characters
  464.      that follow `C-x'.
  465.    * `help-map' is used for characters that follow `C-h'.
  466.    * `esc-map' is for characters that follow ESC.  Thus, all Meta
  467.      characters are actually defined by this map.
  468.    * `ctl-x-4-map' is for characters that follow `C-x 4'.
  469.    * `mode-specific-map' is for characters that follow `C-c'.
  470.    The definition of a prefix key is just the keymap to use for
  471. looking up the following character.  Actually, the definition is
  472. sometimes a Lisp symbol whose function definition is the following
  473. character keymap.  The effect is the same, but it provides a command
  474. name for the prefix key that can be used as a description of what the
  475. prefix key is for.  Thus, the binding of `C-x' is the symbol
  476. `Ctl-X-Prefix', whose function definition is the keymap for `C-x'
  477. commands, the value of `ctl-x-map'.
  478.    Prefix key definitions of this sort can appear in either the global
  479. map or a local map.  The definitions of `C-c', `C-x', `C-h' and ESC as
  480. prefix keys appear in the global map, so these prefix keys are always
  481. available.  Major modes can locally redefine a key as a prefix by
  482. putting a prefix key definition for it in the local map.
  483.    A mode can also put a prefix definition of a global prefix
  484. character such as `C-x' into its local map.  This is how major modes
  485. override the definitions of certain keys that start with `C-x'.  This
  486. case is special, because the local definition does not entirely
  487. replace the global one.  When both the global and local definitions of
  488. a key are other keymaps, the next character is looked up in both
  489. keymaps, with the local definition overriding the global one as usual.
  490.  So, the character after the `C-x' is looked up in both the major
  491. mode's own keymap for redefined `C-x' commands and in `ctl-x-map'.  If
  492. the major mode's own keymap for `C-x' commands contains `nil', the
  493. definition from the global keymap for `C-x' commands is used.
  494.    A keymap is actually a Lisp object.  The simplest form of keymap is
  495. a Lisp vector of length 128.  The binding for a character in such a
  496. keymap is found by indexing into the vector with the character as an
  497. index.  A keymap can also be a Lisp list whose car is the symbol
  498. `keymap' and whose remaining elements are pairs of the form `(CHAR .
  499. BINDING)'.  Such lists are called "sparse keymaps" because they are
  500. used when most of the characters' entries will be `nil'.  Sparse
  501. keymaps are used mainly for prefix characters.
  502.    Keymaps are only of length 128, so what about Meta characters, whose
  503. codes are from 128 to 255?  A key that contains a Meta character
  504. actually represents it as a sequence of two characters, the first of
  505. which is ESC.  So the key `M-a' is really represented as `ESC a', and
  506. its binding is found at the slot for `a' in `esc-map'.
  507. File: emacs,  Node: Rebinding,  Next: Disabling,  Prev: Keymaps,  Up: Key Bindings
  508. Changing Key Bindings Interactively
  509. -----------------------------------
  510.    The way to redefine an Emacs key is to change its entry in a keymap. 
  511. You can change the global keymap, in which case the change is
  512. effective in all major modes (except those that have their own
  513. overriding local definitions for the same key).  Or you can change the
  514. current buffer's local map, which affects all buffers using the same
  515. major mode.
  516. `M-x global-set-key RET KEY CMD RET'
  517.      Defines KEY globally to run CMD.
  518. `M-x local-set-key RET KEY CMD RET'
  519.      Defines KEY locally (in the major mode now in effect) to run CMD.
  520.    For example,
  521.      M-x global-set-key RET C-f next-line RET
  522. would redefine `C-f' to move down a line.  The fact that CMD is read
  523. second makes it serve as a kind of confirmation for KEY.
  524.    These functions offer no way to specify a particular prefix keymap
  525. as the one to redefine in, but that is not necessary, as you can
  526. include prefixes in KEY.  KEY is read by reading characters one by one
  527. until they amount to a complete key (that is, not a prefix key). 
  528. Thus, if you type `C-f' for KEY, that's the end; the minibuffer is
  529. entered immediately to read CMD.  But if you type `C-x', another
  530. character is read; if that is `4', another character is read, and so
  531. on.  For example,
  532.      M-x global-set-key RET C-x 4 $ spell-other-window RET
  533. would redefine `C-x 4 $' to run the (fictitious) command
  534. `spell-other-window'.
  535.    The most general way to modify a keymap is the function
  536. `define-key', used in Lisp code (such as your `.emacs' file). 
  537. `define-key' takes three arguments: the keymap, the key to modify in
  538. it, and the new definition.  *Note Init File::, for an example. 
  539. `substitute-key-definition' is used similarly; it takes three
  540. arguments, an old definition, a new definition and a keymap, and
  541. redefines in that keymap all keys that were previously defined with
  542. the old definition to have the new definition instead.
  543. File: emacs,  Node: Disabling,  Prev: Rebinding,  Up: Key Bindings
  544. Disabling Commands
  545. ------------------
  546.    Disabling a command marks the command as requiring confirmation
  547. before it can be executed.  The purpose of disabling a command is to
  548. prevent beginning users from executing it by accident and being
  549. confused.
  550.    The direct mechanism for disabling a command is to have a non-`nil'
  551. `disabled' property on the Lisp symbol for the command.  These
  552. properties are normally set up by the user's `.emacs' file with Lisp
  553. expressions such as
  554.      (put 'delete-region 'disabled t)
  555.    If the value of the `disabled' property is a string, that string is
  556. included in the message printed when the command is used:
  557.      (put 'delete-region 'disabled
  558.           "Text deleted this way cannot be yanked back!\n")
  559.    You can make a command disabled either by editing the `.emacs' file
  560. directly or with the command `M-x disable-command', which edits the
  561. `.emacs' file for you.  *Note Init File::.
  562.    Attempting to invoke a disabled command interactively in Emacs
  563. causes the display of a window containing the command's name, its
  564. documentation, and some instructions on what to do immediately; then
  565. Emacs asks for input saying whether to execute the command as
  566. requested, enable it and execute, or cancel it.  If you decide to
  567. enable the command, you are asked whether to do this permanently or
  568. just for the current session.  Enabling permanently works by
  569. automatically editing your `.emacs' file.  You can use `M-x
  570. enable-command' at any time to enable any command permanently.
  571.    Whether a command is disabled is independent of what key is used to
  572. invoke it; it also applies if the command is invoked using `M-x'. 
  573. Disabling a command has no effect on calling it as a function from Lisp
  574. programs.
  575. File: emacs,  Node: Syntax,  Next: Init File,  Prev: Key Bindings,  Up: Customization
  576. The Syntax Table
  577. ================
  578.    All the Emacs commands which parse words or balance parentheses are
  579. controlled by the "syntax table".  The syntax table says which
  580. characters are opening delimiters, which are parts of words, which are
  581. string quotes, and so on.  Actually, each major mode has its own syntax
  582. table (though sometimes related major modes use the same one) which it
  583. installs in each buffer that uses that major mode.  The syntax table
  584. installed in the current buffer is the one that all commands use, so we
  585. call it "the" syntax table.  A syntax table is a Lisp object, a vector
  586. of length 256 whose elements are numbers.
  587. * Menu:
  588. * Entry: Syntax Entry.    What the syntax table records for each character.
  589. * Change: Syntax Change.  How to change the information.
  590. File: emacs,  Node: Syntax Entry,  Next: Syntax Change,  Prev: Syntax,  Up: Syntax
  591. Information about Each Character
  592. --------------------------------
  593.    The syntax table entry for a character is a number that encodes six
  594. pieces of information:
  595.    * The syntactic class of the character, represented as a small
  596.      integer.
  597.    * The matching delimiter, for delimiter characters only.  The
  598.      matching delimiter of `(' is `)', and vice versa.
  599.    * A flag saying whether the character is the first character of a
  600.      two-character comment starting sequence.
  601.    * A flag saying whether the character is the second character of a
  602.      two-character comment starting sequence.
  603.    * A flag saying whether the character is the first character of a
  604.      two-character comment ending sequence.
  605.    * A flag saying whether the character is the second character of a
  606.      two-character comment ending sequence.
  607.    The syntactic classes are stored internally as small integers, but
  608. are usually described to or by the user with characters.  For example,
  609. `(' is used to specify the syntactic class of opening delimiters. 
  610. Here is a table of syntactic classes, with the characters that specify
  611. them.
  612.      The class of whitespace characters.
  613.      The class of word-constituent characters.
  614.      The class of characters that are part of symbol names but not
  615.      words.  This class is represented by `_' because the character `_'
  616.      has this class in both C and Lisp.
  617.      The class of punctuation characters that do not fit into any other
  618.      special class.
  619.      The class of opening delimiters.
  620.      The class of closing delimiters.
  621.      The class of expression-adhering characters.  These characters are
  622.      part of a symbol if found within or adjacent to one, and are part
  623.      of a following expression if immediately preceding one, but are
  624.      like whitespace if surrounded by whitespace.
  625.      The class of string-quote characters.  They match each other in
  626.      pairs, and the characters within the pair all lose their syntactic
  627.      significance except for the `\' and `/' classes of escape
  628.      characters, which can be used to include a string-quote inside the
  629.      string.
  630.      The class of self-matching delimiters.  This is intended for TeX's
  631.      `$', which is used both to enter and leave math mode.  Thus, a
  632.      pair of matching `$' characters surround each piece of math mode
  633.      TeX input.  A pair of adjacent `$' characters act like a single
  634.      one for purposes of matching
  635.      The class of escape characters that always just deny the following
  636.      character its special syntactic significance.  The character
  637.      after one of these escapes is always treated as alphabetic.
  638.      The class of C-style escape characters.  In practice, these are
  639.      treated just like `/'-class characters, because the extra
  640.      possibilities for C escapes (such as being followed by digits)
  641.      have no effect on where the containing expression ends.
  642.      The class of comment-starting characters.  Only single-character
  643.      comment starters (such as `;' in Lisp mode) are represented this
  644.      way.
  645.      The class of comment-ending characters.  Newline has this syntax
  646.      in Lisp mode.
  647.    The characters flagged as part of two-character comment delimiters
  648. can have other syntactic functions most of the time.  For example, `/'
  649. and `*' in C code, when found separately, have nothing to do with
  650. comments.  The comment-delimiter significance overrides when the pair
  651. of characters occur together in the proper order.  Only the list and
  652. sexp commands use the syntax table to find comments; the commands
  653. specifically for comments have other variables that tell them where to
  654. find comments.  And the list and sexp commands notice comments only if
  655. `parse-sexp-ignore-comments' is non-`nil'.  This variable is set to
  656. `nil' in modes where comment-terminator sequences are liable to appear
  657. where there is no comment; for example, in Lisp mode where the comment
  658. terminator is a newline but not every newline ends a comment.
  659. File: emacs,  Node: Syntax Change,  Prev: Syntax Entry,  Up: Syntax
  660. Altering Syntax Information
  661. ---------------------------
  662.    It is possible to alter a character's syntax table entry by storing
  663. a new number in the appropriate element of the syntax table, but it
  664. would be hard to determine what number to use.  Therefore, Emacs
  665. provides a command that allows you to specify the syntactic properties
  666. of a character in a convenient way.
  667.    `M-x modify-syntax-entry' is the command to change a character's
  668. syntax.  It can be used interactively, and is also the means used by
  669. major modes to initialize their own syntax tables.  Its first argument
  670. is the character to change.  The second argument is a string that
  671. specifies the new syntax.  When called from Lisp code, there is a
  672. third, optional argument, which specifies the syntax table in which to
  673. make the change.  If not supplied, or if this command is called
  674. interactively, the third argument defaults to the current buffer's
  675. syntax table.
  676.   1. The first character in the string specifies the syntactic class. 
  677.      It is one of the characters in the previous table (*note Syntax
  678.      Entry::.).
  679.   2. The second character is the matching delimiter.  For a character
  680.      that is not an opening or closing delimiter, this should be a
  681.      space, and may be omitted if no following characters are needed.
  682.   3. The remaining characters are flags.  The flag characters allowed
  683.      are
  684.     `1'
  685.           Flag this character as the first of a two-character comment
  686.           starting sequence.
  687.     `2'
  688.           Flag this character as the second of a two-character comment
  689.           starting sequence.
  690.     `3'
  691.           Flag this character as the first of a two-character comment
  692.           ending sequence.
  693.     `4'
  694.           Flag this character as the second of a two-character comment
  695.           ending sequence.
  696.    A description of the contents of the current syntax table can be
  697. displayed with `C-h s' (`describe-syntax').  The description of each
  698. character includes both the string you would have to give to
  699. `modify-syntax-entry' to set up that character's current syntax, and
  700. some English to explain that string if necessary.
  701. File: emacs,  Node: Init File,  Prev: Syntax,  Up: Customization
  702. The Init File, .emacs
  703. =====================
  704.    When Emacs is started, it normally loads the file `.emacs' in your
  705. home directory.  This file, if it exists, should contain Lisp code. 
  706. It is called your "init file".  The command line switches `-q' and
  707. `-u' can be used to tell Emacs whether to load an init file (*note
  708. Entering Emacs::.).
  709.    There can also be a "default init file", which is the library named
  710. `default.el', found via the standard search path for libraries.  The
  711. Emacs distribution contains no such library; your site may create one
  712. for local customizations.  If this library exists, it is loaded
  713. whenever you start Emacs.  But your init file, if any, is loaded
  714. first; if it sets `inhibit-default-init' non-`nil', then `default' is
  715. not loaded.
  716.    If you have a large amount of code in your `.emacs' file, you
  717. should move it into another file named `SOMETHING.el', byte-compile it
  718. (*note Lisp Libraries::.), and make your `.emacs' file load the other
  719. file using `load'.
  720. * Menu:
  721. * Init Syntax::     Syntax of constants in Emacs Lisp.
  722. * Init Examples::   How to do some things with an init file.
  723. * Terminal Init::   Each terminal type can have an init file.
  724. File: emacs,  Node: Init Syntax,  Next: Init Examples,  Prev: Init File,  Up: Init File
  725. Init File Syntax
  726. ----------------
  727.    The `.emacs' file contains one or more Lisp function call
  728. expressions.  Each of these consists of a function name followed by
  729. arguments, all surrounded by parentheses.  For example, `(setq
  730. fill-column 60)' represents a call to the function `setq' which is
  731. used to set the variable `fill-column' (*note Filling::.) to 60.
  732.    The second argument to `setq' is an expression for the new value of
  733. the variable.  This can be a constant, a variable, or a function call
  734. expression.  In `.emacs', constants are used most of the time.  They
  735. can be:
  736. Numbers:
  737.      Numbers are written in decimal, with an optional initial minus
  738.      sign.
  739. Strings:
  740.      Lisp string syntax is the same as C string syntax with a few extra
  741.      features.  Use a double-quote character to begin and end a string
  742.      constant.
  743.      Newlines and special characters may be present literally in
  744.      strings.  They can also be represented as backslash sequences:
  745.      `\n' for newline, `\b' for backspace, `\r' for carriage return,
  746.      `\t' for tab, `\f' for formfeed (control-l), `\e' for escape,
  747.      `\\' for a backslash, `\"' for a double-quote, or `\OOO' for the
  748.      character whose octal code is OOO.  Backslash and double-quote are
  749.      the only characters for which backslash sequences are mandatory.
  750.      `\C-' can be used as a prefix for a control character, as in
  751.      `\C-s' for ASCII Control-S, and `\M-' can be used as a prefix for
  752.      a meta character, as in `\M-a' for Meta-A or `\M-\C-a' for
  753.      Control-Meta-A.
  754. Characters:
  755.      Lisp character constant syntax consists of a `?' followed by
  756.      either a character or an escape sequence starting with `\'. 
  757.      Examples: `?x', `?\n', `?\"', `?\)'.  Note that strings and
  758.      characters are not interchangeable in Lisp; some contexts require
  759.      one and some contexts require the other.
  760. True:
  761.      `t' stands for `true'.
  762. False:
  763.      `nil' stands for `false'.
  764. Other Lisp objects:
  765.      Write a single-quote (') followed by the Lisp object you want.
  766. File: emacs,  Node: Init Examples,  Next: Terminal Init,  Prev: Init Syntax,  Up: Init File
  767. Init File Examples
  768. ------------------
  769.    Here are some examples of doing certain commonly desired things with
  770. Lisp expressions:
  771.    * Make TAB in C mode just insert a tab if point is in the middle of
  772.      a line.
  773.           (setq c-tab-always-indent nil)
  774.      Here we have a variable whose value is normally `t' for `true'
  775.      and the alternative is `nil' for `false'.
  776.    * Make searches case sensitive by default (in all buffers that do
  777.      not override this).
  778.           (setq-default case-fold-search nil)
  779.      This sets the default value, which is effective in all buffers
  780.      that do not have local values for the variable.  Setting
  781.      `case-fold-search' with `setq' affects only the current buffer's
  782.      local value, which is not what you probably want to do in an init
  783.      file.
  784.    * Make Text mode the default mode for new buffers.
  785.           (setq default-major-mode 'text-mode)
  786.      Note that `text-mode' is used because it is the command for
  787.      entering the mode we want.  A single-quote is written before it
  788.      to make a symbol constant; otherwise, `text-mode' would be
  789.      treated as a variable name.
  790.    * Turn on Auto Fill mode automatically in Text mode and related
  791.      modes.
  792.           (setq text-mode-hook
  793.             '(lambda () (auto-fill-mode 1)))
  794.      Here we have a variable whose value should be a Lisp function. 
  795.      The function we supply is a list starting with `lambda', and a
  796.      single quote is written in front of it to make it (for the
  797.      purpose of this `setq') a list constant rather than an
  798.      expression.  Lisp functions are not explained here, but for mode
  799.      hooks it is enough to know that `(auto-fill-mode 1)' is an
  800.      expression that will be executed when Text mode is entered, and
  801.      you could replace it with any other expression that you like, or
  802.      with several expressions in a row.
  803.           (setq text-mode-hook 'turn-on-auto-fill)
  804.      This is another way to accomplish the same result. 
  805.      `turn-on-auto-fill' is a symbol whose function definition is
  806.      `(lambda () (auto-fill-mode 1))'.
  807.    * Load the installed Lisp library named `foo' (actually a file
  808.      `foo.elc' or `foo.el' in a standard Emacs directory).
  809.           (load "foo")
  810.      When the argument to `load' is a relative pathname, not starting
  811.      with `/' or `~', `load' searches the directories in `load-path'
  812.      (*note Loading::.).
  813.    * Load the compiled Lisp file `foo.elc' from your home directory.
  814.           (load "~/foo.elc")
  815.      Here an absolute file name is used, so no searching is done.
  816.    * Rebind the key `C-x l' to run the function `make-symbolic-link'.
  817.           (global-set-key "\C-xl" 'make-symbolic-link)
  818.      or
  819.           (define-key global-map "\C-xl" 'make-symbolic-link)
  820.      Note once again the single-quote used to refer to the symbol
  821.      `make-symbolic-link' instead of its value as a variable.
  822.    * Do the same thing for C mode only.
  823.           (define-key c-mode-map "\C-xl" 'make-symbolic-link)
  824.    * Redefine all keys which now run `next-line' in Fundamental mode
  825.      so that they run `forward-line' instead.
  826.           (substitute-key-definition 'next-line 'forward-line
  827.                                      global-map)
  828.    * Make `C-x C-v' undefined.
  829.           (global-unset-key "\C-x\C-v")
  830.      One reason to undefine a key is so that you can make it a prefix. 
  831.      Simply defining `C-x C-v ANYTHING' would make `C-x C-v' a prefix,
  832.      but `C-x C-v' must be freed of any non-prefix definition first.
  833.    * Make `$' have the syntax of punctuation in Text mode.  Note the
  834.      use of a character constant for `$'.
  835.           (modify-syntax-entry ?\$ "." text-mode-syntax-table)
  836.    * Enable the use of the command `eval-expression' without
  837.      confirmation.
  838.           (put 'eval-expression 'disabled nil)
  839. File: emacs,  Node: Terminal Init,  Prev: Init Examples,  Up: Init File
  840. Terminal-specific Initialization
  841. --------------------------------
  842.    Each terminal type can have a Lisp library to be loaded into Emacs
  843. when it is run on that type of terminal.  For a terminal type named
  844. TERMTYPE, the library is called `term/TERMTYPE' and it is found by
  845. searching the directories `load-path' as usual and trying the suffixes
  846. `.elc' and `.el'.  Normally it appears in the subdirectory `term' of
  847. the directory where most Emacs libraries are kept.
  848.    The usual purpose of the terminal-specific library is to define the
  849. escape sequences used by the terminal's function keys using the library
  850. `keypad.el'.  See the file `term/vt100.el' for an example of how this
  851. is done.
  852.    When the terminal type contains a hyphen, only the part of the name
  853. before the first hyphen is significant in choosing the library name. 
  854. Thus, terminal types `aaa-48' and `aaa-30-rv' both use the library
  855. `term/aaa'.  The code in the library can use `(getenv "TERM")' to find
  856. the full terminal type name.
  857.    The library's name is constructed by concatenating the value of the
  858. variable `term-file-prefix' and the terminal type.  Your `.emacs' file
  859. can prevent the loading of the terminal-specific library by setting
  860. `term-file-prefix' to `nil'.
  861.    The value of the variable `term-setup-hook', if not `nil', is
  862. called as a function of no arguments at the end of Emacs
  863. initialization, after both your `.emacs' file and any
  864. terminal-specific library have been read in.  You can set the value in
  865. the `.emacs' file to override part of any of the terminal-specific
  866. libraries and to define initializations for terminals that do not have
  867. a library.
  868.